<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>吉他教室</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <nav class="navbar navbar-default" role="navigation">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                            <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="#">Dawei</a>
                    </div>
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <form class="navbar-form navbar-left" role="search" onsubmit="return false;">
                            <div class="form-group">
                                <input type="text" id="keyword" class="form-control" />
                            </div>
                            <button type="submit" class="btn btn-default" id="btn_submit">Submit</button>
                        </form>
                    </div>
                </nav>
                <div class="jumbotron">
                    <div id="msg"></div>
                    <div id="images"></div>
                    <div id="history">
                        <p>近期查询记录</p>
                        <ul>
                            <foreach name="log" item="item">
                            <li class="log"><a data-href="{$item.url}">{$item.title}</a></li>
                            </foreach>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
    $("#btn_submit").click(function(){
    	url = $('#keyword').val();
    	if(!url){
    		$("#msg").html('请输入网址');
    		return false;
    	}
    	$.ajax({
    		url:"{:U('Dawei/index')}",
    		data: {url:url},
    		type: "post",
    		success:function(data){
    			console.log(data)
    			if(data.flag){
    				$("#msg").html('查询结果：');
    				$.each(data.data, function(key, image_url){
    					$("#images").append('<img alt="140x140" src="'+image_url+'" class="img-thumbnail" />');
    				})
    			}else{
                    $("#msg").html(data.msg);
    			}
    		},
    		beforeSend:function(){
    			$("#msg").html('正在查询');
    			$("#images").html('');
    		},
    	});
    });
    $(".log a").click(function(){
    	url = $(this).attr('data-href');
    	$('#keyword').val(url);
    });
    </script>
</body>
</html>